<?php
	session_start();
	header("Content-Type:text/html;charset=utf-8");

	
	if( $_SESSION["current_user"] != NULL )
	{
		include_once("conn.php");
		echo "您已经登录了：";
		echo $_SESSION["current_user"];
		echo "\n";
		
		$sql = "select * from tb_user_info where name='".$_SESSION["current_user"]."'";
		$result=mysql_query($sql);
		while($gotActnum = mysql_fetch_array($result) )
		{
			if( $gotActnum["actnum"]  !="1" )
			{
				echo "未激活本帐号,请通过点击激活邮件的链接来激活您的帐号";
				echo "<br>";
				echo '<a href=resent.php>重新发送激活邮件</a>';
			}
			
		}

		echo '	<form action="login_out.php" method="post">
					<tr>
						<td><input type="hidden"  name="loginout" value="loginout" /></td>
						<td><input type="submit" value="注销登录" /></td>
					</tr>
	
				</form>
			';
		
		echo '<a href="public.php">去我的发布页</a>';
	}
	
	
	else
	{
		echo '
	

	<div id="login_go.php" style="middle">
	<form action="login_go.php" method="post" align="center">
		<tr>
			<td>用户名：</td>
			<td><input type="text" id="username" name="username" /></td>
		</tr>

		<tr>
			<td>密码</td>
			<td><input type="password" id="password" name="password" /></td>
		</tr>

		<tr>
			<input type="radio" name="day1" value="day1" />记住一天
			<input type="radio" name="day1" value="month1" />记住一月
			<td><input type="submit" value="提交" /></td>
			<td><input type="reset" value="重置" /></td>
		</tr>
	
	</form>
	</div>
	<div>
		<form align="center">
			<a href="signup.php">注册新用户!</a>
		</form>
	</div>
	';
	}
?>


<!--	/*以上为登录界面*/ -->




<html>
<head>
    <meta charset="UTF-8">
	<link href="mycss.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="jquery-1.7.1.js"></script>

	<script type="text/javascript">
	
	
	function change_cate(catecid,catecid2)
	{
		var catename=$("div#"+catecid+" "+"input#edit_cate_name").val();
		console.log( "div#"+catecid+" "+"input#edit_cate_name" );
		var oldname=$("div#"+catecid+" "+"input#delcate_action").val();
		$.post("show_cate.php",{name11:catename,name22:oldname},function(newname){
			$("div#"+catecid2).html(newname);
		});
	}


	</script>
	
	
	
	<script>
	function show_add_link(abc)
	{
		var obj=document.getElementById(abc);
		if(obj.style.display=='none')
		{
			obj.style.display='block';
		}
		else
		{
			obj.style.display='none';
		}
	}

	

	function cate_modify(a)
	{
		var obj=document.getElementById(a);
		if(obj.style.display=="none")
		{
			obj.style.display='block';
		}
		else
		{
			obj.style.display='none';
		}
	}

	function judge(a)
	{
		var obj=document.getElementById(a);
		if(obj.style.display=='block')
			return 1;
		else
			return 0;
	}
	

	function show_edit_link(abc)
	{
		var obj2=document.getElementById(abc);
		if(obj2.style.display=="none")
		{
			obj2.style.display="block";
		}
		else
		{
			obj2.style.display="none";
		}
	}

	</script>
	

</head>
<?php
	/*
	function link_check()
	{
		if( preg_match("www\.([a-zA-Z0-9]\w{0,44}[a-zA-Z0-9]\.(com|com\.cn|net|org|info|mobi))|([a-zA-Z0-9]\w{0,44}[a-zA-Z0-9](?!CHINA|CHINESE)\.cn)",) )
		{

		}
	}
	*/
	function show()
	{
		echo "<div class='heading' align='middle' float:right>";
			echo $_POST["newcategory"];
			echo "<div class='controls'>";
				echo "<a href='#' class='add_link' onclick=show_add_link('add_cate_link".$_POST["newcategory"]."');return false;>";
				echo "<img src='/元素/image/tiny_plus.png'>";
				echo "</a>";
				echo "<a href='#' class='divider' >";
				echo "</a>";
				echo "<a href='#' class='modify' onclick=cate_modify('".$_POST["newcategory"]."');return false; >";
				echo "<img src='/元素/image/tiny_gear.png'>";
				echo "</a>";
			echo "</div>";
		echo "</div>";

		/* 以下为增加分类中的增加网址模块 */
		echo "<div class='add_link_form'  id='add_cate_link".$_POST["newcategory"]."' style='padding-top:15px;padding-right:15px;padding-bottom-15px;padding-left:15px;display:none;' align='middle'>";
		
		echo "<form action='index.php' method='post'>";
		
		echo "<input type='hidden' name='is_link_submit' value='yes' />";
		echo "<input type='hidden' name='cname' value='$cid' />";
		echo "<input type='text' name='link_name' placeholder='input your link name' />";
		echo "<input type='text' name='link_address' placeholder='create your new link' />";
		echo "<input type='submit' value='create link' />";
		
		echo "</form>";
		
		echo "</div>";
		
		/* 以上为增加分类中的网址模块 */

	
		/* 以下为修改分类信息模块*/
		echo "<div class='edit_cate_form' id='".$_POST["newcategory"]."' style='display:none'; align='middle'> ";
		echo "<form action='cate_process.php' method='post'> ";
		
		echo "<input type='text' name='edit_cate_name' value='".$got["cate_name"]."' />";
		echo "<input type='hidden' name='delcate_action' value='".$got["cate_name"]."' /> ";
		echo "<input type='submit' name='save_cate' id='save_cate' value='save' />";
		echo "<input type='submit' name='del_cate' id='del_cate' value='delete'/>";
		echo "</form>";
		echo "</div>";

		/*  以上为修改分类信息模块*/
		

	}
	
	include_once("c_add_link.php");
	include_once("c_add_cate.php");
	include_once("conn.php");

	echo "<div id='wrapper' align='middle'>";
	echo "<form method='post' action='index.php'>";
	echo "<input type='text' name='newcategory' placeholder='在此输入要新创建的分类' style='width:320px;height:20px;'  />";
	echo "<input type='hidden' name='action' value='create' />";
	echo "<input type='submit' value='create' name='submit'>";
	echo "</form>";
	echo "</div>";
	$sql="select cate_name,cid from category where category.name='".$_SESSION["current_user"]."'";
	mysql_query("set names utf-8");
	$result=mysql_query($sql,$conn);
	echo "<div id='container' align='middle'>";
	if($result)
	{
		while($got=mysql_fetch_array($result))
		{
			$cid=$got["cid"];
			$cname=$got["cate_name"];
			echo "<div class='heading'>";
				echo "<div class='change_cate_style' id='".$cid."' style='float:left;'>";
				echo $got["cate_name"];
				echo "</div>";
				//$cid=$got["cid"];
				echo "<div class='controls'>";
					echo "<a href='#' class='add_link' onclick=show_add_link('add_cate".$got["cate_name"]."');return false;>";
					echo "<img src='../元素/image/tiny_plus.png'>";
					echo "</a>";
					echo "<a href='#' class='divider' >";
					echo "</a>";
					echo "<a href='#' class='modify' onclick=cate_modify('".$got["cate_name"]."');return false;>";
					echo "<img src='/元素/image/tiny_gear.png'>";
					echo "</a>";
				echo "</div>";
			echo "</div>";
			/* 以下为增加分类中的增加网址模块 */
			echo "<div class='add_link_form'  id='add_cate".$got["cate_name"]."' style='padding-top:15px;padding-right:15px;padding-bottom-15px;padding-left:15px;display:none;'>";
			
			echo "<form action='index.php' method='post'>";
			
			echo "<input type='hidden' name='is_link_submit' value='yes' />";
			echo "<input type='hidden' name='cname' value='$cid' />";
			echo "<input type='text' name='link_name' placeholder='input your link name' />";
			echo "<input type='text' name='link_address' placeholder='create your new link' />";
			echo "<input type='submit' value='create link' />";
			
			echo "</form>";
			
			echo "</div>";
			
			/* 以上为增加分类中的网址模块 */
			
			/* 以下为修改分类信息模块*/
			echo "<div class='edit_cate_form' id='".$cname."' style='display:none';> ";
			echo "<form action='cate_process.php' method='post' > ";
			
			echo "<input type='text' class='cate_style' id='edit_cate_name' name='edit_cate_name' value='".$got["cate_name"]."' />";
			echo "&nbsp&nbsp&nbsp";
			echo "<input type='hidden' name='delcate_action' id='delcate_action' value='".$got["cate_name"]."' /> ";
			echo "<input type='hidden' name='cid2' id='cid2' value='".$cid."' />" ;
			echo "&nbsp&nbsp";
			echo "<input type='button' class='save_cate_style' name='save_cate' id='save_cate' value='save' onclick=\"change_cate('".$cname."',".$cid.");return false;\" />";
			echo "<input type='submit' name='del_cate' id='del_cate' value='delete'/>";


			echo "</form>";
			echo "</div>";

			/*  以上为修改分类信息模块*/
			

			$got_catename=$got["cate_name"];
			echo "<div class='link'>";
			$sql2="select category.cate_name,link.lid,webname,webaddress from category,cate_link,link where category.cid=cate_link.cid && link.lid=cate_link.lid ";
			mysql_query("set names utf-8");
			$result2=mysql_query($sql2);
			if($result2)
			{
				while($got_cate=mysql_fetch_array($result2))
				{
					if($got_cate["cate_name"]==$got_catename)
					{
						echo "<div class='link_line'>";
							echo $got_cate["webname"];
							$temp_webname=$got_cate["webname"];
							echo "&nbsp";
							echo "&nbsp";
							echo $got_cate["webaddress"];
							//$temp_webaddress=$got_cate["webaddress"];
							//$temp_lid=$got_cate["lid"];
							//$lid=$got_cate["lid"];
							echo "<div class='controls'>";
								echo "<a href='#' onclick=show_edit_link('edit_link_".$got_cate["lid"]."');>";
									echo "<img src=/元素/image/tiny_gear.png >";
								echo "</a>";
							echo "</div>";
						echo "</div>";
						/*以下为编辑链接FORM*/
						echo "<div id='edit_link_".$got_cate["lid"]."' style='display:none;'>"; 
							echo "<form method='post' action='link_process.php' name='".$got_cate["webname"]."'>";
							echo "<input type='text' name='alias' value='$got_cate[webname]' />";
							echo "<input type='text' name='alias_name' value='$got_cate[webaddress]'/>";
							echo "<input type='hidden' name='save' value='save' />";
							echo "<input type='hidden' name='".$got_cate["lid"]."' value='".$got_cate["webname"]."' />";
							echo "<input type='hidden' name='real_webname' value='".$got_cate["webname"]."' /> ";
							echo "<input type='submit' name='save_link' value='save' />";
							echo "<input type='submit' name='del_link' value='delete' />";
							echo "</form>";
						echo "</div>";
						/*以上为编辑链接FORM*/

					}

				}
			}
			else
			{
				echo "链接数据库读取失败";
			}
			

			


			echo "</div>";
		}
	}
	else
	{
		echo "读取分类数据库失败";
	}
	echo "</div>";

	$receive_new_cate=new addCate();

	if($_POST["action"]==create && $_POST["newcategory"]!=NULL && $_SESSION["current_user"]!=NULL )
	{
		
		$receive_new_cate->addC();
		show();
		echo "<meta http-equiv='refresh' content='0.5'; url='index.php' />";
	}
	else if( $_POST["action"]==create && $_SESSION["current_user"] == NULL )
	{
		echo "<script language='javascript'>alert('请先登录！');</script>";
	}

?>
</html>